package com.pai4j.jianlipai.service.jianlibot;
import com.pai4j.common.enums.PromptTemplateEnum;
import com.pai4j.common.service.FreeMarkEngineService;
import com.pai4j.common.util.AiResponseUtil;
import com.pai4j.domain.dto.llm.ChatCompletionMessage;
import com.pai4j.domain.dto.llm.ChatCompletionResponse;
import com.pai4j.domain.dto.llm.ChatMessageRole;
import com.pai4j.jianlipai.service.MoonshotAIService;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 *  简历分析服务
 *
 * @author: CYM-pai
 * @date: 2025/05/06 12:40
 **/
@Slf4j
@Service
public class JianLiPaiAnalysisService {


    @Resource
    private MoonshotAIService moonshotAIService;
    @Resource
    private FreeMarkEngineService freeMarkEngineService;

    private String aiAutoGenResumeJSON(String content, String jsonTemplate) {
        Map<String, Object> vars = new HashMap<>();
        vars.put("json", jsonTemplate);
        vars.put("content", content);
        try {
            String prompt = freeMarkEngineService.getContentByTemplate(PromptTemplateEnum.RESUME_JSON.getPath(), vars);
            final List<ChatCompletionMessage> messageList = Arrays.asList(
                    new ChatCompletionMessage(ChatMessageRole.SYSTEM.value(), "你是一个简历文档分析助手"),
                    new ChatCompletionMessage(ChatMessageRole.USER.value(), prompt));
            ChatCompletionResponse chatCompletionResponse = moonshotAIService.chat(messageList);
            return AiResponseUtil.getJsonString(chatCompletionResponse.getChoices().get(0).getMessage().getContent());
        } catch (Exception e) {
            log.error("===>aiAutoComment error.", e);
        }
        return null;
    }
}
